#*-*encoding:utf-8-*-
import json
import yaml
import os
import traceback
import copy
import rospy
import time

from acupoint_msgs.msg import AcupointCoordinate


def loadYaml(file_path):
    if not os.path.exists(file_path):
        print("Error, %s not exists"%file_path)
        return
    yaml_data=None
    
    try:
        with open(file_path) as f:
            yaml_data=yaml.safe_load(f.read())
    except:
        print("Some error occured,the exception message is:")
        print(traceback.format_exc())
    return yaml_data


class ActionPub:
    def __init__(self):
        self.massage_actions=None
        # self.action_pub=rospy.Publisher("/massage/massage_actions",Bool,queue_size=1)
        
    
    def loadYaml(self,file_path):
        if not os.path.exists(file_path):
            print("Error, %s not exists"%file_path)
            return
        yaml_data=None
        try:
            with open(file_path) as f:
                yaml_data=yaml.safe_load(f.read())
        except:
            print("Some error occured,the exception message is:")
            print(traceback.format_exc())
        return yaml_data

    def looping(self):
        pass
        

def acupointCallback(msg):
    print("U are in callback")
    global acupoint_coordinate
    global acupoint_name
    acupoint_coordinate=copy.deepcopy(msg).acupoints
    acupoint_name=copy.deepcopy(msg).name
    # print(acupoint_coordinate)
    # print(acupoint_name)
    


if __name__=='__main__':
    global acupoint_coordinate
    global acupoint_name
    temp=loadYaml('./waist.yaml')
    print(temp)
    actions=temp['actions']
    print(actions)
    print(actions[0])
  
    
    for action in temp['actions']:
        action['name']='l_'+action['name']
        print(action['name'])
        # index=acupoint_name.index(action['name'])
        # print(acupoint_coordinate[index])
    print(temp)
    with open('./temp.yaml','w') as f:
        yaml.dump(temp, f)
    